//! $Id: TypeInfo.h 25 2009-10-15 07:17:24Z skagget77 $
//!
//! @file    TypeInfo.h
//! @author  Johan Andersson <skagget77@gmail.com>
//! @date    Fri Oct 02 07:35 2009
//! @ingroup IoCpp
//!

#if !defined(IOCPP_TYPEINFO_H)
#define IOCPP_TYPEINFO_H

#include <typeinfo>

namespace IoCpp
{
   //!
   //! @author  Johan Andersson <skagget77@gmail.com>
   //! @date    Fri Oct 02 07:35 2009
   //! @ingroup IoCpp
   //!
   //! The TypeInfo class, a copyable and assignable wrapper around the C++
   //! standard library's type_info class.
   //!
   class TypeInfo
   {
   public :
      //!
      //! Constructor, creates a new instance of the TypeInfo class.
      //!
      TypeInfo()
         : typeinfo(0) {
      }

      //!
      //! Constructor, creates a new instance of the TypeInfo class from the
      //! specified type_info instance.
      //!
      //! @param info The type_info instance.
      //!
      TypeInfo( const std::type_info& info )
         : typeinfo(&info) {
      }

      //!
      //! Copy constructor, creates a new instance of the TypeInfo class from
      //! the specified TypeInfo instance.
      //!
      //! @param info The TypeInfo instance to copy.
      //!
      TypeInfo( const TypeInfo& info )
         : typeinfo(info.typeinfo) {
      }

      //!
      //! Assignment operator, assigns the specified TypeInfo class to this
      //! instance.
      //!
      //! @param  info The TypeInfo instance.
      //!
      //! @return This instance after assignment.
      //!
      TypeInfo& operator=( const TypeInfo& info )
      {
         typeinfo = info.typeinfo;
         return *this;
      }

      //!
      //! Compares this instance to the specified TypeInfo instance.
      //!
      //! @param  info The TypeInfo instance to compare this instance to.
      //!
      //! @return True if this instance comes before the specified instance,
      //!         false otherwise.
      //!
      bool Before( const TypeInfo& info ) const {
         return typeinfo->before(*info.typeinfo) != 0;
      }

      //!
      //! Returns the implementation defined name of the type represented by
      //! the wrapped type_info class.
      //!
      //! @return The implementation defined name.
      //!
      std::string Name() const {
         return typeinfo->name();
      }

   private :
      const std::type_info* typeinfo;
   };


   //!
   //! Compare two TypeInfo instances for order.
   //!
   //! @param  lhs The left hand side of the comparison.
   //!
   //! @param  rhs The right hand side of the comparison.
   //!
   //! @return True if lhs comes before rhs, false otherwise.
   //!
   inline bool operator<( const TypeInfo& lhs, const TypeInfo& rhs ) {
      return lhs.Before(rhs);
   }
}

#endif   // IOCPP_TYPEINFO_H
